All Questions
Tagged with javaprogramming-practices
135 questions
0votes
1answer
239views
Is immutable objects over POJO in general?
Lombok is used in the legacy project where I am currently working for since last year. The project is legacy with 10+ years, and POJO/JavaBeans, i.e. @Data annotated classes, have been widely used for ...
2votes
4answers
3kviews
I wrote a class with "init" method. Should I call it from other class methods? Or leave it to the object user? (Code Design)
I have a java class with an init method. It's different from the constructor. The constructor just initializes the variables/fields. The init method connects to a database and performs some ...
1vote
4answers
341views
Storing both a compiled service for a Docker container as well as the container in a repository. Good practice, bad practice or no precedent?
This has erupted from quite a turbulent meeting between two senior developers, a lead developer and an engineering lead, and after 90mins reached no resolution. We create Spring Boot Java services ...
-1votes
1answer
16kviews
@Getter, @Setter vs @Data in lombok? [closed]
So I was sending code for review and approvals for some changes I made recently. that includes a class as below: import lombok.Getter; import lombok.Setter; @Getter @Setter public class ...
2votes
1answer
1kviews
Does it make sense to use byte instead of int in Java? [duplicate]
Recently, I had to implement a business rule in a certain project. The rule basically consisted of checking a range between 1 and 12, values that would be used later, in some way, with Bootstrap. ...
-1votes
2answers
262views
Do I really need TaskManager class? [duplicate]
Background: I'm coding an app, the core idea is simple - I can choose a 'Task' (consists of name, code to perform aka Runnable, progress) through GUI, start it, stop it, start all 'Task's and stop all ...
3votes
4answers
780views
Is it a bad practice to have an interface method to tell whether it can handle an object?
interface Resolver { boolean canResolve(SomeInput input); SomeOutput resolve(SomeInput input); } public static void main(String[] args) { List<Resolver> resolvers = ...; ...
9votes
2answers
1kviews
Should function names describe their parameter types?
If you wish to perform the same action using different parameters, you can either make differently named functions: public Apple findAppleById(long id){ return repo.findById(id); } public Apple ...
1vote
2answers
497views
Is using KDoc/Javadoc comments inside of a function considered bad practice?
I often find it helpful to use KDoc/Javadoc comments inside of a class or function instead of normal comments. IntelliJ colorizes them more obviously by default and, more importantly, allows ...
3votes
2answers
207views
Checking the user in almost all use cases
I have a web application that has Users that belong to Companies. A User can only belong to 1 Company at a time and they can manage their own company information. I'm using java spring and I'm ...
4votes
3answers
1kviews
Passing object or using the field
I would like to know what is a more appropriate way to code in Java. Is it generally better to pass entire objects in the method's parameters or just using the fields from the class? Using the field: ...
-3votes
1answer
269views
Is it good practice to use try/catch like Python in Java?
I mainly use Python and just started learning Java. For now, I've tried using try/catch for basic file read/write as follows public String[] readFile(String fileName){ try{ // read file } ...
0votes
3answers
202views
When using a DSL to structure my application, should I favor coupling the code with the DSL, or trying to have majority of my code independent of it?
We're currently using the Apache Camel Java DSL to structure our application, but I guess this question can mostly apply to any DSL in general. Now, amongst our developers, we are divided on two polar ...
2votes
4answers
2kviews
Separating data and behavior in Java
I am in the process of refining my code to adhere more to my current understanding of the Single Responsibility Principle (SRP). Originally, I had a class called Animal that had a set of methods and ...
2votes
3answers
1kviews
When is it appropriate to reuse a method for another method?
I am writing a program that describes different properties on a single Management Company's plot of land. For this program there are 3 overloaded addProperty method's. My question is I can reuse the ...